[NPU] Adapt LoRA and expert handling to Megatron Core 0.18 and TENPU - #189
Draft
addsubmuldiv wants to merge 1 commit into
Draft
[NPU] Adapt LoRA and expert handling to Megatron Core 0.18 and TENPU#189addsubmuldiv wants to merge 1 commit into
addsubmuldiv wants to merge 1 commit into
Conversation
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adapt the NPU model configuration and LoRA integration to Megatron Core 0.18 with MegatronAdaptor and TransformerEngineNPU (TENPU), removing the dependency on MindSpeed-specific APIs.
Companion integration: modelscope/ms-swift#10087
Changes
ModelConfig.TELinearfor NPU LoRA adapters instead of selecting annn.Linearfallback by MindSpeed version.TELayerNormColumnParallelLinear, obtain the linear output and post-normalization activation from one base-layer forward usingreturn_layernorm_output. Preserve the bias contract and restore the original flag infinally, rather than reconstructing normalization through MindSpeed private methods._tp_groupas the TP-group fallback.TEGroupedLinearand expert configuration, rather than a MindSpeed module name. Pass expert tensor/data-parallel groups when constructing grouped LoRA sharded checkpoint tensors.Validation
Tested together with the companion Swift change on Ascend 910B3, Python 3.12, CANN 9.1.0, PyTorch 2.10.0, torch_npu 2.10.0.post2, and Transformers 5.12.1. Backend snapshots: MCore
ba7b5ebce12a(0.18.0), MegatronAdaptor2a164d4548e2, and TENPU0a389a677586.no_save_optim; it does not establish MoE optimizer-resume correctness.7.82e-5.merge_lora=false: matching logged loss across continuous training and two successive resume stages.These are bounded 2–4-step integration checks, not long-run or full-size-model qualification. GPU/FP8 paths were not tested.
Scope and known limitation
USE_MCORE_GDNand LoRA merge/export behavior are unchanged. BF16 in-place merge followed by subtraction-based unmerge can change training weights through rounding; exact restoration/non-mutating export is a separate follow-up, not fixed here. Usemerge_lora=falsewhen validating uninterrupted-versus-resumed LoRA training equivalence.